package cn.itqiqi.student_system_java.controller;

import cn.itqiqi.student_system_java.pojo.ScoreAddVo;
import cn.itqiqi.student_system_java.service.ScoreService;
import cn.itqiqi.student_system_java.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kevin_琪琪
 * @version 1.0
 * @description
 * @date 2022-06-20 18:38
 */
@RestController
public class ScoreController {

    @Autowired
    private ResultUtils resultUtils;
    @Autowired
    private ScoreService scoreService;

    @GetMapping("/getScoreData")
    public String getScoreData(Long pageNum, Long pageSize){
        return scoreService.getScoreData(pageNum, pageSize);
    }

    @GetMapping("/getCourseAll")
    public String getCourseAll(){
        return scoreService.getCourseAll();
    }

    @GetMapping("/getStuAll")
    public String getStuAll(){
        return scoreService.getStuAll();
    }

    @GetMapping("/getScoreBy")
    public String getScoreBy(Long pageNum, Long pageSize, String selectValue, String queryValue) {

        if (selectValue.equals("sname")) {
            return scoreService.getCourseByName(pageNum, pageSize, queryValue);
        } else if (selectValue.equals("cname")) {
            return scoreService.getCourseByCourse(pageNum, pageSize, queryValue);
        } else {
            return resultUtils.fail(400, "参数不合法!");
        }

    }

    @PostMapping("/scoreAdd")
    public String scoreAdd(@RequestBody String scoreAddVo) {
        return scoreService.scoreAdd(scoreAddVo);
    }

    @PostMapping("/updateScore")
    public String updateScore(@RequestBody String score) {
        return scoreService.updateScore(score);
    }

    @PostMapping("/deleteScore")
    public String deleteScore(@RequestBody String score) {
        return scoreService.deleteScore(score);
    }

}
